package com.qxglxt.qxglxt.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.qxglxt.qxglxt.dao.IModulesDao;
import com.qxglxt.qxglxt.model.Modules;
import com.qxglxt.qxglxt.service.IModulesService;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/module")
public class ModulesController {
    @Resource
    private IModulesDao modulesDao;

    @ApiOperation(value = "查询所有模块",notes = "查询所有模块")
    @GetMapping("/findAllModules")
    public Map<String ,Object> findAllModlues(){
        List<Modules> list=modulesDao.findAll();
        Map<String ,Object> map=new HashMap<String ,Object>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", modulesDao.count());
        map.put("data", list);
        return map;
    }
    @ApiOperation(value = "新增模块",notes = "新增模块")
    @PostMapping("/addModule")
    public Modules addModule(@RequestBody Modules m){
        return modulesDao.save(m);
    }
    @ApiOperation(value = "更新模块",notes = "更新模块")
    @PutMapping("/editModule")
    private Modules editModule(@RequestBody Modules m){
        return modulesDao.save(m);
    }
    @ApiOperation(value = "删除模块",notes = "删除模块")
    @ApiImplicitParam(name="id",value = "模块编号",required = true,paramType = "path")
    @DeleteMapping("/{id}")
    public void delModule(@PathVariable Integer id){
        modulesDao.deleteById(id);
    }


    @ApiOperation(value = "获取角色权限",notes = "获取角色权限")
    @GetMapping("/findRoleModules/{roleId}")
    public List<Modules> findRoleModules(String roleId){
        return modulesSevice.findRolesModules(roleId);
    }
}